#include <iostream>
#include "RessourceManager.h"
#include "Audio.h"

using namespace JDL;
using namespace std;

Audio::Audio()
{
  _repeat_track = false;
  _repeat_playlist = false;
}

Audio::~Audio()
{
  
}

void	Audio::PlayMusic(const string str)
{
  if (_playlist.find(str) != _playlist.end())
    Mix_PlayMusic(_playlist[str], 0);
  else
    {
      this->AddMusic(str);
      Mix_PlayMusic(_playlist[str], 0);
    }
}

void	Audio::PlaySound(const string str)
{
  if (_sounds.find(str) != _sounds.end())
    Mix_PlayChannel(-1, _sounds[str], 0);
  else
    {
      this->AddSound(str);
      Mix_PlayChannel(-1, _sounds[str], 0);
    }
  
}

void	Audio::AddMusic(const string str)
{

  RessourceManager::GetInstance()->AddMusic(str);
  _playlist[str] = RessourceManager::GetInstance()->GetMusic(str);
}

void	Audio::AddSound(const string str)
{
  RessourceManager::GetInstance()->AddSound(str);
  _sounds[str] = RessourceManager::GetInstance()->GetSound(str);
}

void	Audio::SetRepeatTrack()
{
  _repeat_track = true;
}

void	Audio::SetRepeatPlaylist()
{
  _repeat_playlist = true;
}
